package com.reyco1.platformengine.core
{
	import com.reyco1.platformengine.map.IMap;
	import com.reyco1.platformengine.tile.BaseTile;
	import com.reyco1.platformengine.vo.CornersData;

	public class CoordinateUtil
	{
		public function CoordinateUtil()
		{
			super();
		}
		
		public static function getCorners(character:*, currentMap:IMap, gameEngine:GameEngine, x:Number, y:Number):CornersData
		{
			var cornersObject:CornersData = new CornersData();
			
			cornersObject.downY  = Math.floor((y + (character.height * 0.5) - 1) / currentMap.tileH);
			cornersObject.upY 	 = Math.floor((y - (character.height * 0.5)) 	 / currentMap.tileH);
			cornersObject.leftX  = Math.floor((x - (character.width * 0.5)) 	 / currentMap.tileW);
			cornersObject.rightX = Math.floor((x + (character.width * 0.5) - 1)  / currentMap.tileW);
			
			cornersObject.upleft 	= BaseTile(gameEngine.getChildByName("tile_" + cornersObject.upY 	+ "_" + cornersObject.leftX)).walkable;
  			cornersObject.downleft 	= BaseTile(gameEngine.getChildByName("tile_" + cornersObject.downY 	+ "_" + cornersObject.leftX)).walkable;
  			cornersObject.upright 	= BaseTile(gameEngine.getChildByName("tile_" + cornersObject.upY	+ "_" + cornersObject.rightX)).walkable;
  			cornersObject.downright = BaseTile(gameEngine.getChildByName("tile_" + cornersObject.downY 	+ "_" + cornersObject.rightX)).walkable;
			
			return cornersObject;
		}
		
		public static function getTile(gameEngine:GameEngine, coord1:Number, coord2:Number):BaseTile
		{
			var baseTile:BaseTile = BaseTile(gameEngine.getChildByName("tile_" + coord1 + "_" + coord2));
			return baseTile;
		}
		
	}
}